package com.cc.eb.controller;

import com.cc.eb.model.EbProduct;
import com.cc.eb.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2022/1/7 16:52
 */
@Controller
@RequestMapping("product")
public class ProductController {

    @Resource
    private ProductService  productService;

    @RequestMapping("/detail")
    public String detail(Model model, int pid){
        System.out.println("进入ProductController的detail方法....pid："+pid);
        //1.调用 service查询该 pid的 商品详情
        EbProduct productDetail = productService.detail(pid);
        //2.绑定数据model
        model.addAttribute("productDetail",productDetail);
        //3.返回view
        return "product-view";//templates/product-view.html
    }

    @RequestMapping("/add_car")
    public String addCar(int epId, HttpServletRequest request){
        //1.TODO 调用service将商品加入购物车
        productService.addCar(epId,request);
        //2.TODO 绑定数据到model--数据
        //不需要因为在service已经将数据放到session中了
        //3.TODO  返回view --html
        return "shopping";
    }

    @RequestMapping("/pay")
    public String pay(){
        //TODO 1.返回view
        return "shopping-result";
    }

}
